package me.xADudex.RandomLocation;

import org.bukkit.block.*;
import org.bukkit.*;
import org.bukkit.inventory.ItemStack;

public class BlockData
{
    private int id;
    private byte data;
    
    public BlockData(final int id, final byte data) {
        this.data = -1;
        this.id = id;
        this.data = data;
    }
    
    public BlockData(final int id) {
        this.data = -1;
        this.id = id;
    }
    
    public BlockData(final String data) {
        this.data = -1;
        if (data.contains(":")) {
            this.id = StringTools.getInteger(data.split(":")[0]);
            final int d = StringTools.getInteger(data.split(":")[1]);
            if (d <= 127) {
                this.data = (byte)d;
            }
        }
        else {
            this.id = StringTools.getInteger(data);
        }
    }
    
    public void setId(final int id) {
        this.id = id;
    }
    
    public void setData(final byte data) {
        this.data = data;
    }
    
    public boolean hasData(final Block b) {
        return this.hasData(b.getTypeId(), b.getData());
    }
    
    public boolean hasData(final int id, final byte data) {
        return this.id == id && (this.data == -1 || data == this.data);
    }
    
    public boolean hasData(final Location loc) {
        return this.hasData(loc.getBlock());
    }
    
    @Override
    public String toString() {
        if (this.data == -1) {
            return new StringBuilder(String.valueOf(this.id)).toString();
        }
        return String.valueOf(this.id) + ":" + this.data;
    }
}
